The invention relates generally to the field of digital computers and more specifically to functional units for processing predetermined types of instructions. The invention particularly provides a circuit or functional unit for use in connection with execution of an instruction for rearranging bits of a data word in accordance with a mask.
Computers process data in accordance with instructions. One type of instruction which has been proposed is a so-called xe2x80x9cminglexe2x80x9d instruction which accepts as operands a data word and a mask word and rearranges the bits of the data word in accordance with the mask word. In the rearranged data word, the bits of the data word in bit positions towards the left end of the data word are distributed to bit positions which correspond to bit positions of the mask whose bits are clear, or have the value xe2x80x9czero,xe2x80x9d and the bits of the data word in bit positions to the right end of the data word are distributed to bit positions which correspond to bit positions of the mask whose bits are set, while maintaining order of the bits of the data word in each group. For example, if an eight bit data word has the value xe2x80x9cabcdefghxe2x80x9d (where the letters represent binary integers having the value xe2x80x9conexe2x80x9d or xe2x80x9czeroxe2x80x9d), and the mask word corresponds to xe2x80x9c10011011,xe2x80x9d in the rearranged data word generated when the xe2x80x9cmingle instruction is executed with these as operands, since three of the eight mask bits are clear the leftmost three bits xe2x80x9ca,xe2x80x9d xe2x80x9cbxe2x80x9d and xe2x80x9ccxe2x80x9d of the data word will be distributed to the bit positions of the mask word which are clear, and since five of the mask bits are set the rightmost bits xe2x80x9cdxe2x80x9d through xe2x80x9chxe2x80x9d will be distributed to the bit positions of the mask word which are set, preserving order in each group, providing output xe2x80x9cdabefcgh.xe2x80x9d
In a variant of the xe2x80x9cminglexe2x80x9d instruction, the bits of the rearranged data word in bit positions for which the bits of the mask are either set or clear (but preferably not both) will be set to a predetermined value. Generally, it has been proposed that, for example, the bits of the rearranged data word in bit positions for which the bits of the mask are clear will be set to zero, but the variant may be used with either group, and the predetermined value may be either xe2x80x9conexe2x80x9d or xe2x80x9czero.xe2x80x9d
A xe2x80x9cminglexe2x80x9d instruction can find utility in connection with, for example, performing various bit permutations, for example, using a mask consisting of alternating set and clear bits will result in a so-called xe2x80x9cshufflexe2x80x9d permutation of a data word.
The invention provides a new and improved circuit or functional unit for use in connection with execution of an instruction for rearranging bits of a data word in accordance with a mask.
In brief summary, the invention provides a system for rearranging an input data word in relation to a mask word, the data word comprising a plurality of input data units in a series of input data unit positions, each associated with a respective one of a plurality of bits of the mask word in a series of mask bit positions, each mask bit having one of a plurality of conditions, to provide an output data word comprising a plurality of output data units in a series of output data unit positions. The system comprises a control module and a shift module. The control module is configured to identify, for each output data unit position, the number of bits in bit positions in the mask word to one end of that bit position which have one of the conditions, and the number of bits in bit positions to another end of the mask word have another of the conditions. The shift module is configured to shift the input data units from their respective input data unit positions each of the bit positions into the respective output data unit positions in response to the identifications generated by the control module and the conditions of the respective mask bits.